// 描述：跨平台 api

(function(KIT, RES) {
  "use strict";

  var E = rapid.html.Element,
    ButtonBuilder = rapid.html.ButtonBuilder,
    func_buildButtons = rapid.html._buildButtons_,
    func_getButtonKey = rapid.ui.Button._getKey_;

    // 具体路径在具体项目中（project.js)配置
  RES.URL_ROOT = "";
  RES.URL_API = RES.URL_ROOT + "/api";

  RES.ARR_WHETHER = [{text: "是", value: "1"}, {text: "否", value: "0"}];
  RES.ARR_SEX = [{text: "男", value: 1}, {text: "女", value: 0}];
  RES.ARR_STATE = [{text: "启用", value: 1}, {text: "禁用", value: 0}];

  RES.CSS_TITLE = "r-bold r-h9s";
  RES.CSS_TITLE_LG = "r-bold r-h9";
  RES.CSS_GRID_ROW = "r-p-rl r-p-tb-xs r-clearfix r-bd-12-3 r-bg-0-2 g-grid-row r-shadow-bottom";
  RES.CSS_GRID_ROW_TITLE_WRAP = "r-p-t r-p-b-sm";
  RES.CSS_GRID_ROW_BLOCK = "r-p-t-sm r-p-b-xs";
  RES.CSS_GRID_ROW_ILINE = "r-m-r";



  KIT.avatar = function(options) {
    var __o = rapid.extend({
      bdColor: "r-bd-12-1",
      bgColor: "r-bg-12-1",
      foreColor: "r-cl-12-6",
      size: null,
      icon: "fa-user",
      image: null,
      border: false,
      circle: true,
      corner: true
    }, options);

    var __icon_size = "r-h9";

    switch(__o.size) {
      case "xxs":
        __o.size = "r-size-xxs";
        break;

      case "xs":
        __icon_size = "r-h8s";
        __o.size = "r-size-xs";
        break;

      case "sm":
        __icon_size = "r-h8";
        __o.size = "r-size-sm";
        break;

      case "lg":
        __icon_size = "r-h7";
        __o.size = "r-size-lg";
        break;

      case "xl":
        __icon_size = "r-h6s";
        __o.size = "r-size-xl";
        break;

      case "xxl":
        __icon_size = "r-h6";
        __o.size = "r-size-xxl";
        break;

      default:
        __icon_size = "r-h7s";
        __o.size = "r-size";
        break;
    }

    var __circle = __o.circle ? " r-circle" : "",
      __border = __o.border ? " r-bd r-bd-bold" : "",
      __corner = __o.corner && !__o.circle ? " r-corner-all" : "";

    if(rapid.str.hasValue(__o.image)) {
      return E.view({
          cssClass: "r-img-wrap-w " + __o.size + " " + __o.bdColor + __circle + __border + __corner
        },
        E.image({src: __o.image})
      );
    }

    return E.view({
        cssClass: "r-flex-v r-flex-al-m r-flex-al-c r-img-wrap-wh " + __o.bgColor + " " + __o.foreColor + " " +
                  __o.size + " " + __o.bdColor + __circle + __border + __corner
      },
      E.view({cssClass: "fas fa-user " + __icon_size})
    );
  };

  //region navibar
  KIT.navibar = function() {
    return E("div").addClass("r-clearfix", "r-bg-0-1", "r-bd-tb", KIT.BD_COLOR, "g-navi");
  };
  KIT.navibar_home = function() {
    return E("div").addClass("r-f-l", "r-p", "g-navi-item")
                   .html(
                     E("span").addClass("fas", "fa-home", "r-p-rl-xs", "r-icon")
                   );
  };
  KIT.navibar_item = function(text) {
    return E("div").addClass("r-f-l", "r-p", "g-navi-item")
                   .append(E("span").addClass("fal", "fa-angle-right", "r-p-r", "r-icon"))
                   .append(E("span").addClass("r-ilblock", "r-bold", "r-text").html(text));
  };
  KIT.appendNavibarItem = function(navibarElm, text, attrs) {
    rapid(navibarElm).lastChild().addClass("r-cl-8-3 r-bg-1-0h r-cl-1-6h r-bg-1-0a r-cl-1-6a").end()
                     .append(
                       KIT.navibar_item(text).attrs(attrs)
                     );
  };
  //endregion

  //region sgrid
  KIT.grid_row = function() {
    return E("div").addClass(RES.CSS_GRID_ROW);
  };
  KIT.grid_block = function(content) {
    return E("div").addClass(RES.CSS_GRID_ROW_BLOCK).html(
      rapid.isArray(content) ?
      E.each(content, function(c) {
        return c;
      }) : content
    );
  };
  KIT.grid_inline = function(content, spaceSize) {
    return E("div").addClass("r-ilblock", "r-al-m", rapid.nvl(spaceSize, "r-m-r", function(v) {
      return v === null ? "" : "r-m-r-" + v;
    })).html(
      rapid.isArray(content) ?
      E.each(content, function(c) {
        return c;
      }) : content
    );
  };
  KIT.grid_inline_all = function(content, spaceSize) {
    return E("div").addClass("r-ilblock", "r-al-m", rapid.nvl(spaceSize, "r-m-r", function(v) {
      return v === null ? "" : "r-m-r-" + v;
    })).html(
      rapid.isArray(content) ?
      E.each(content, function(c) {
        return E("div").addClass("r-ilblock", "r-al-m", "r-m-r-sm").html(c);
      }) : content
    );
  };

  KIT.grid_img = function(src, size, circle) {
    if(rapid.str.hasValue(size)) {
      size = "r-size-" + size;
    } else {
      size = "r-size";
    }

    return E("div").addClass("r-img-wrap-w", size).toggleClass("g-circle", rapid.nvl(circle, false)).html(
      E("img").toggleAttr("src", src, rapid.hasValue(src))
    );
  };

  KIT.grid_title = function(title, subTitle) {
    return E("div").addClass(RES.CSS_GRID_ROW_TITLE_WRAP)
                   .append(
                     E("span")
                       .toggleClass("r-p-r", rapid.hasValue(subTitle))
                       .addClass("r-ilblock", "r-al-m", RES.CSS_TITLE).html(title)
                   )
                   .append(
                     rapid.hasValue(subTitle) ?
                     E("span").addClass("r-ilblock", "r-al-b", "r-cl-8-3").html(subTitle) : ""
                   )
  };
  KIT.grid_title_lg = function(title, subTitle) {
    return E("div").addClass(RES.CSS_GRID_ROW_TITLE_WRAP)
                   .append(
                     E("span").addClass(RES.CSS_TITLE_LG).html(title)
                   )
                   .append(
                     rapid.hasValue(subTitle) ?
                     E("span").addClass("r-h9s").html(" (" + subTitle + ")") : ""
                   )
  };

  KIT.grid_label = function(text, color) {
    return E("div").addClass("r-ilblock", "r-al-m", color === false ? "" : (rapid.isUndefined(color) ? "r-cl-8-3" : color)).html(text + "：");
  };
  KIT.grid_label_wrap = function(label, content, color) {
    return E("div").addClass("r-ilblock", "r-al-m", "r-nowrap").append(
      KIT.grid_label(label, color)
    ).append(
      rapid.isArray(content) ?
      E.each(content, function(c) {
        return E("div").addClass("r-ilblock", "r-al-m", "r-m-r-sm").html(c);
      }) :
      E("div").addClass("r-ilblock", "r-al-m", "r-m-r-lg").html(content)
    );
  };

  KIT.grid_action_add = function(text, tag) {
    return {
      cssClass: "fn-add", text: "新建" + rapid.nvl(text) + "...", icon: "fa-plus", color: 1,
      tag: tag
    };
  };
  KIT.grid_action_edit = function(tag) {
    return {
      cssClass: "fn-edit", text: "编辑...", icon: "fa-pencil", color: 2,
      tag: tag
    };
  };
  KIT.grid_action_remove = function(tag) {
    return {
      cssClass: "fn-remove", text: "删除", icon: "fa-trash-alt", color: 6,
      tag: tag
    };
  };
  KIT.grid_actions = function() {
    var __actions = "",
      __arg_size = arguments.length,
      __btn, __i, __j;

    if(__arg_size === 1 && rapid.isArray(arguments[0])) {
      return KIT.grid_actions.apply(this, arguments[0]);
    }

    for(__i = 0; __i < __arg_size; __i++) {
      __btn = arguments[__i];

      if(rapid.hasValue(__btn)) {
        __actions +=
          ButtonBuilder.tostring({
            cssClass: (__i < __arg_size - 1 ? "r-m-r-lg" : "") + (__btn.cssClass ? " " + __btn.cssClass : ""),
            icon: rapid.nvl(__btn.icon, null),
            text: __btn.text,
            focusable: false,
            color: rapid.nvl(__btn.color, 11),
            style: rapid.nvl(__btn.style, "link"),
            tag: rapid.nvl(__btn.tag)
          });
      }
    }

    return E("div").addClass("g-sgrid-actions").html(__actions);
  };

  // 绑定事件
  KIT.bindGridActionEvent = function(selector, action, callback) {
    rapid(selector).on("click", ".g-sgrid-actions > ." + action, function() {
      return callback.apply(rapid.ui(this), arguments);
    });
  };
  KIT.bindGridAddEvent = function(selector, callback) {
    rapid(selector).on("click", ".g-sgrid-actions > .fn-add", function() {
      return callback.apply(rapid.ui(this), arguments);
    });
  };
  KIT.bindGridEditEvent = function(selector, callback) {
    rapid(selector).on("click", ".g-sgrid-actions > .fn-edit", function() {
      return callback.apply(rapid.ui(this), arguments);
    });
  };
  KIT.bindGridRemoveEvent = function(selector, callback) {
    rapid(selector).on("click", ".g-sgrid-actions > .fn-remove", function() {
      return callback.apply(rapid.ui(this), arguments);
    });
  };
  KIT.bindGridQuickRemoveEvent = function(selector, callback) {
    rapid(selector).on("click", ".g-sgrid-actions > .fn-remove", function() {
      var __s = this,
        __args = arguments;

      rapid.confirm("确定要删除吗？", function(e) {
        if(e) {
          return callback.apply(rapid.ui(__s), __args);
        }
      });
    });
  };

  (function() {
    var _create = function(ui) {
        var __o = ui.__o__,
          __R_el = rapid(ui.element);

        __R_el.addClass("r-widget-el " + ui.__cn__ + " " +  + KIT.BD_COLOR)
              .wrap("<div class=\"r-grid-wrap\"></div>")
              .html(
                _createToolbar(ui) +
                E("div").addClass("r-border-box", "r-sgrid-body", "r-bd-tb",  + KIT.BD_COLOR) +
                E("div").addClass("r-grid-pagination")
              );

        ui.__d_wrap = __R_el.parent()[0];

        var __R_cld = __R_el.children();

        ui.__d_bar = __R_cld.filter(".r-grid-bar")[0];
        ui.__d_dataBody = __R_cld.filter(".r-sgrid-body")[0];

        _initPagination(ui, __R_cld.filter(".r-grid-pagination"));

        _saveToolButtonElements(ui);

        if(!__o.pageable) {
          ui.__oo_pagination.hide().disabled(true);
        } else {
          __R_el.addClass("r-bd-b");
        }
      },

      _createToolbar = function(ui) {
        var __o_toolbar = ui.__o__.toolbar,
          __p_tool_button_handlers = ui.__p_toolButtonHandlers,
          __d_tool_buttons = ui.__d_toolButtons,
          __el = E("div").addClass("r-border-box r-p-xs r-clearfix r-grid-bar");

        if(rapid.hasValue(__o_toolbar)) {
          if(!rapid.isArray(__o_toolbar)) {
            if(rapid.isFunction(__o_toolbar)) {
              __o_toolbar = __o_toolbar();
            }

            __el.html(__o_toolbar);

          } else {
            __el.html(func_buildButtons(__o_toolbar, false, function(opt, index) {
              var __key = func_getButtonKey(opt);
              __p_tool_button_handlers[__key] = opt.handler;
              __d_tool_buttons[__key] = index;
            }).join(""));
          }

        } else {
          __el.addClass("r-hide");
        }

        return __el;
      },

      _saveToolButtonElements = function(ui) {
        var __R_btns = rapid(ui.__d_bar).children(".r-button"),
          __p_tool_button_handlers = ui.__p_toolButtonHandlers,
          __d_tool_buttons = ui.__d_toolButtons;

        for(var __key in __p_tool_button_handlers) {
          __d_tool_buttons[__key] = __R_btns[__d_tool_buttons[__key]];
        }
      },

      _initPagination = function(ui, R_pagination) {
        ui.__oo_pagination = rapid(R_pagination)
          .pagination(rapid.extend(true, {}, ui.__o__.pagination, {registrable: false}))
          .on("page", function() {
            ui.__oo_datakit.page(this.pageIndex());
            rapid(ui.element).children(".r-sgrid").scrollTop(0);
          })
          .on("sizeChange", function() {
            ui.__oo_datakit.pageSize(this.pageSize()).page(1);
            rapid(ui.element).scrollTop(0);
          })
          .on("refresh", function() {
            ui.__oo_datakit.reload();
          });
      },

      _setDataKit = function(ui) {
        var __o = ui.__o__;

        ui.__oo_datakit = rapid.DataKit({
          load: rapid.nvl(__o.load, {}),
          pageable: __o.pageable

        }).on("loadSuccess", function(rs, msg) {
          ui.__oo_events.invoke("loadSuccess", ui, rs);

          if(__o.pageable) {
            _bindData(ui, rs.list);
            ui.__oo_pagination.bind(rs.recordCount, rs.pageIndex);

          } else {
            _bindData(ui, rs);
          }
        });
      },

      _resizeGrid = function(ui) {
        var __R_data_body = rapid(ui.__d_dataBody),
          __height;

        if(ui.__oo_events.contains("resize")) {
          __height = rapid.nvl(ui.__oo_events.invoke("resize", ui), 0) -
                     rapid(ui.element).borderHeight() -
                     rapid(ui.__oo_pagination.element).outerHeight(true) -
                     rapid(ui.__d_bar).outerHeight(true);

        } else {
          __height = rapid(window).height() - rapid.nvl(rapid(".r-body").paddingHeight(), 0) -
                     rapid.nvl(rapid("#pageContent1").outerHeight(true), 0) -
                     rapid(ui.element).borderHeight() -
                     rapid(ui.__oo_pagination.element).outerHeight(true) -
                     rapid(ui.__d_bar).outerHeight(true);//36;
        }

        __R_data_body.css("height", rapid.parseEM(__height));
      },

      _bindData = function(ui, data) {
        var __i = 0,
          __len = rapid.isEmpty(data) ? 0 : data.length,
          __R_data_body = rapid(ui.__d_dataBody);

        if(__len === 0) {
          __R_data_body.empty();
          return;
        }

        var __html = "",
          __events = ui.__oo_events,
          __row_spacing = "r-m-b-lg",
          __row_el;

        for(__i; __i < __len; __i++) {
          __row_el = __events.invoke("itemdatabound", ui, data[__i]);

          if(rapid.hasValue(__row_el)) {
            __html += (__i === 0 ? KIT.grid_row().addClass(__row_spacing).html(__row_el) :
                       KIT.grid_row().addClass("r-bd-t", __row_spacing).html(__row_el));
          }
        }

        __R_data_body.html(__html);
      };

    rapid.ui.WidgetBase.create("SGrid", null, {
      _initProps_: function(options) {
        rapid.ui.SGrid.base._initProps_.call(this, options);

        this.__p_toolButtonHandlers = {};

        this.__d_bar = null;
        this.__d_dataBody = null;
        this.__d_toolButtons = {};

        this.__oo_datakit = null;
        this.__oo_pagination = null;
      },
      init: function() {
        _create(this);

        _setDataKit(this);
        _resizeGrid(this);

        var __s = this;
        rapid(window).on("resize.sgrid", function() {
          _resizeGrid(__s);
        });

        this._register_();

        this.__oo_events.invoke("init", this);

        return this;
      },

      clear: function() {
        rapid(this.__d_dataBody).empty();
        if(this.__o__.pageable) {
          this.__oo_pagination.bind(null);
        }

        return this;
      },

      load: function() {
        var __arg_size = arguments.length,
          __o = this.__o__;

        if(__arg_size !== 0) {
          var __page_index = 1,
            __param = arguments[0];

          if(__arg_size > 1) {
            __page_index = rapid.nvl(arguments[1], 1);
            __page_index = __page_index <= 0 ? 1 : __page_index;
          }

          if(rapid.isJson(__param)) {

            if(rapid.isEmpty(__param)) {
              __o.load = {};
              this.__oo_datakit = null;

            } else {
              rapid.extend(true, __o.load, __param);
              _setDataKit(this);

              if(__page_index === 1) {
                this.__oo_datakit.load(__param);
              } else {
                this.__oo_datakit.page(__page_index);
              }
            }

            return this;
          }
        }

        if(this.__oo_datakit === null) {
          _setDataKit(this);
        }
        this.__oo_datakit.load();

        return this;
      },

      reload: function() {
        var __oo_datakit = this.__oo_datakit;

        if(__oo_datakit !== null) {
          __oo_datakit.reload();
        }

        return this;
      },

      resize: function() {
        _resizeGrid(this);
        return this;
      }
    }, {
      defaults: {
        load: {},
        pageable: false,
        pagination: null
      }
    });
  })();
  //endregion

  /**
   * 输出html字符串
   */
  KIT.html = {
    /**
     * 创建按钮
     * @param options
     * @returns {String}
     */
    button: function(options) {
      return ButtonBuilder.tostring(options);
    },

    /**
     * 添加|新建 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {*|string}
     */
    addButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        icon: "fa-plus",
        tip: "新建..."
      }));
    },

    /**
     * 修改|编辑 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    editButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        icon: "fa-pencil",
        tip: "修改..."
      }));
    },

    /**
     * 删除 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    removeButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        icon: "fa-trash-alt",
        color: 6,
        tip: "删除"
      }));
    },

    /**
     * 保存 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    saveButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        text: "保存",
        color: 3,
        icon: "fa-check"
      }));
    },

    /**
     * 取消 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    cancelButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        text: "取消",
        icon: "fa-ban"
      }));
    },

    /**
     * 刷新 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    refreshButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        icon: "fa-refresh",
        tip: "刷新"
      }));
    },

    /**
     * 查看 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    viewButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        icon: "fa-eye",
        tip: "查看"
      }));
    },

    /**
     * 搜索 按钮
     * @param options {id: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    searchButton: function(options) {
      return ButtonBuilder.tostring(rapid.extend(true, options, {
        text: "搜索",
        color: 3,
        icon: "fa-search"
      }));
    },

    /**
     * 导出 按钮，默认以图标显示，可以自定义文字
     * @param options {id: "", text: "", cssClass: "", tag: {key: "", value: ...}}
     * @returns {String}
     */
    exportButton: function(options) {
      var _options = {};
      if(rapid.isDefined(options.text)) {
        _options.text = options.text;
      }

      return ButtonBuilder(rapid.extend(true, options, {
        icon: "fa-cloud-download",
        tip: "导出"
      }, _options));
    }
  };

  KIT.phoneCode = function(options) {
    options = rapid.extend({
      phoneTarget: null,
      eventTarget: null,
      seconds: 60,
      url: null
    }, options);

    var __CODE_TIMER = null;

    var _startCodeTimer = function(opts) {
        if(__CODE_TIMER == null) {
          var __cl_1 = "r-cl-1-6",
            __cl_gray = "r-cl-8-2",
            __code_times = opts.seconds,
            __target = opts.eventTarget;

          rapid(__target).removeClass(__cl_1).addClass(__cl_gray).html(__code_times + "秒后重新获取");

          __CODE_TIMER = setInterval(function() {
            if(__code_times === 1) {
              clearInterval(__CODE_TIMER);
              __CODE_TIMER = null;

              rapid(__target).removeClass(__cl_gray).addClass(__cl_1).html("重新获取验证码");
              rapid(opts.eventTarget).data("disabled", false);

            } else {
              rapid(__target).html(--__code_times + "秒后重新获取");
            }
          }, 1000);
        }
      },
      _bindEvent = function(opts) {
        rapid(opts.eventTarget).on("click", function() {
          var __phone = opts.phoneTarget,
            __R_button = rapid(this),
            __value = null;

          if(__R_button.data("disabled") === true) {
            return;
          }

          if(__phone instanceof rapid.ui.FormControlBase) {
            __value = __phone.val();
            __phone.valid();

          } else {
            var __ui = rapid.ui(__phone);

            if(__ui instanceof rapid.ui.FormControlBase) {
              __value = __ui.val();
              __ui.valid();

            } else {
              __value = rapid(__phone).val();
            }
          }

          if(rapid.hasValue(__value)) {
            __R_button.data("disabled", true);

            rapid.post({
              url: opts.url,
              data: "phone=" + __value,
              success: function(result) {
                _startCodeTimer(opts);
              },
              fail: function() {
                __R_button.data("disabled", false);
                rapid.fail("请稍后再尝试获取验证码。");
              }
            });
          }
        });
      };

    _bindEvent(options);
  };

  KIT.linkButtonHtml = function(opts) {
    return ButtonBuilder.tostring({
      focusable: false,
      style: "link"
    });
  };

  KIT.textarea = function() {
    return E("textarea")
      .addClass("r-border-box", "r-p-sm", "r-corner-all", "r-bd", KIT.BD_COLOR, "r-bd-1-6h", "r-bd-1-6f", "r-block")
      .css({"box-shadow": "none!important"})
      .attrs({
        "rows": "5"
      });
  };

  /**
   * 将数字转换成中文大写
   * @param n
   * @returns {string}
   * @constructor
   */
  KIT.intToChinese = function(n) {
    if(!/^(0|[1-9]\d*)(\.\d+)?$/.test(n)) {
      return "";
    }
    var unit = "千百拾亿千百拾万千百拾元角分", str = "";
    n += "00";
    var p = n.indexOf('.');
    if(p >= 0) {
      n = n.substring(0, p) + n.substr(p + 1, 2);
    }
    unit = unit.substr(unit.length - n.length);
    for(var i = 0; i < n.length; i++) {
      str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
    }
    return str.replace(/零[千百拾角]/g, "零").replace(/(零)+/g, "零").replace(/零[万亿元]/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
  };

  KIT.buildQrcodeEl = function(id) {
    return E("div").addClass("g-qrcode-wrap").append(
      E("div").addClass("g-qrcode-canvas").attr("id", id)
    ).append(
      E("div").addClass("r-p", "g-qrcode-img-wrap").html(E("img"))
    );
  };

  KIT.qrcode = function(selector, content) {
    // jQuery库支持

    if(!window.jQuery) {
      rapid._error_("qrcode插件需要jQuery支持。");
      return;
    }

    if(!jQuery.fn.qrcode) {
      rapid._error_("没有引用qrcode插件的脚本库。");
      return;
    }

    var __$_code = jQuery(selector);

    if(__$_code.qrcode) {
      __$_code.qrcode({
        text: content
      });
    }

    var __$_wrap = __$_code.next();
    __$_wrap.children().attr("src", rapid.nvl(__$_code.children("canvas")[0].toDataURL("image/png")));

    return __$_wrap;
  };

  // 防止数字过大，显示不全，超过maxValue后，将最大值后面添加+号
  KIT.maxCount = function(value, maxValue) {
    if(value > maxValue) {
      return maxValue + "+";
    }

    return value;
  };

  // 格式化时间，返回“刚刚”，“一小时前”等这样的信息
  KIT.formatMsgTime = function(timespan) {

    var dateTime = rapid.date.parseDate(timespan);

    var year = dateTime.getFullYear();
    var month = dateTime.getMonth() + 1;
    var day = dateTime.getDate();
    var hour = dateTime.getHours();
    var minute = dateTime.getMinutes();
    var second = dateTime.getSeconds();
    var now = new Date();
    var now_new = now.getTime();  //typescript转换写法
    var now_old = dateTime.getTime();
    var milliseconds = 0;
    var timeSpanStr;

    milliseconds = now_new - now_old;

    if(milliseconds <= 1000 * 60 * 1) {
      timeSpanStr = '刚刚';
    } else if(1000 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60) {
      timeSpanStr = Math.round((milliseconds / (1000 * 60))) + '分钟前';
    } else if(1000 * 60 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60 * 24) {
      timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60)) + '小时前';
    } else if(1000 * 60 * 60 * 24 < milliseconds && milliseconds <= 1000 * 60 * 60 * 24 * 15) {
      timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60 * 24)) + '天前';
    } else if(milliseconds > 1000 * 60 * 60 * 24 * 15 && year == now.getFullYear()) {
      timeSpanStr = month + '-' + day + ' ' + hour + ':' + minute;
    } else {
      timeSpanStr = year + '-' + month + '-' + day + ' ' + hour + ':' + minute;
    }
    return timeSpanStr;
  };

})(rapid.kit, rapid.res);